package com.cangchu.ui.activity;

import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;
import com.cangchu.MyApplication;
import com.cangchu.R;
import com.cangchu.util.InjectView;
import com.cangchu.widget.HomeButton;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends BaseActivity<MainActivity> {

	protected static final String TAG = "MainActivity";

	@InjectView(R.id.bt_pandian)
	private HomeButton bt_pandian;//线路设置
	@InjectView(R.id.bt_record)
	private HomeButton bt_record;//乘车打卡
	@InjectView(R.id.bt_record_query)
	private HomeButton bt_record_query;//记录查询
	@InjectView(R.id.bt_data_query)
	private HomeButton bt_data_query;//数据查询
	@InjectView(R.id.bt_common_set)
	private HomeButton bt_common_set;	//通用设置
	@InjectView(R.id.bt_loginout)
	private HomeButton bt_loginout;	//安全退出

	MyApplication app;

	private int keyBackClickCount = 0;

	@Override
	protected void onResume() {
		super.onResume();
		keyBackClickCount = 0;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK) {
			switch (keyBackClickCount++) {
			case 0:
				Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
				Timer timer = new Timer();
				timer.schedule(new TimerTask() {
					@Override
					public void run() {
						keyBackClickCount = 0;
					}
				}, 3000);
				break;
			case 1:
				finish();
				break;
			default:
				break;
			}
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected int getContentViewLayoutID() {
		return R.layout.activity_main;
	}

	@Override
	protected void initViewsAndEvents() {
		//这里的Title 的确是顶部的标题栏
		setTitle("主界面");
		app = getmApplication();

		//清单功能
		bt_pandian.setOnHomeClick(new HomeButton.HomeClickListener() {
			
			@Override
			public void onclick() {
				Intent intent = new Intent(MainActivity.this,checkActivity.class);
				startActivity(intent);
			}


		});

		//批次查询
		bt_record.setOnHomeClick(new HomeButton.HomeClickListener() {
			
			@Override
			public void onclick() {
				Intent intent = new Intent(MainActivity.this,batchActivity.class);
				startActivity(intent);
			}
		});

		//出库
		bt_record_query.setOnHomeClick(new HomeButton.HomeClickListener() {
			
			@Override
			public void onclick() {
				Log.d(TAG,"bt_routeset");
			}
		});

		//商品管理
		bt_data_query.setOnHomeClick(new HomeButton.HomeClickListener() {
			
			@Override
			public void onclick() {
				Log.d(TAG,"文件读写测试");
				Intent intent = new Intent(MainActivity.this,QueryActivity.class);
				startActivity(intent);
			}
		});

		//系统设置
		bt_common_set.setOnHomeClick(new HomeButton.HomeClickListener() {

			@Override
			public void onclick() {
				Log.d(TAG,"bt_routeset");
			}
		});
		
		bt_loginout.setOnHomeClick(new HomeButton.HomeClickListener() {

			@Override
			public void onclick() {
				Log.d(TAG,"bt_routeset");
				finish();
			}
		});
	}

}
